/*
 * lab4.fx
 *
 * Created on 03.11.2009, 17:03:50
 */

package javafx179labs.gromova.lab4;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.animation.Timeline;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.*;
import javafx.scene.shape.Line;
import javafx.scene.transform.Rotate;
import javafx.animation.transition.*;



var luch2Angle=0;
var luch1Angle=0;
var luch3Angle=0;
var luch4Angle=0;
var luch5Angle=0;
var luch6Angle=0;
var luch7Angle=0;
var luch8Angle=0;
var sun : Circle = Circle{
    radius: 30
    centerX:150
    centerY:100
    fill: Color.YELLOW
    onMouseClicked: function(evt: MouseEvent):Void{
        timeline.playFromStart();
    }
}

var luch1 : Line = Line {
    startX: 30
    startY: 100
    endX: 100
    endY: 100
    stroke: Color.YELLOW
    transforms: [
            Rotate{
                pivotX:155
                pivotY:95
                angle:bind luch1Angle
            }
    ]

}

var luch2 : Line = Line {
    startX: 150
    startY: 2
    endX: 150
    endY: 62
    stroke: Color.YELLOW
    transforms: [
            Rotate{
                pivotX:155
                pivotY:105
                angle:bind luch2Angle
            }
    ]

}

var luch3 : Line = Line {
    startX: 200
    startY: 100
    endX: 280
    endY: 100
    stroke: Color.YELLOW
    transforms: [
            Rotate{
                pivotX:155
                pivotY:75
                angle:bind luch3Angle
            }
    ]
}

var luch4 : Line = Line {
    startX: 150
    startY: 140
    endX: 150
    endY: 210
    stroke: Color.YELLOW
    transforms: [
            Rotate{
                pivotX:155
                pivotY:75
                angle:bind luch4Angle
            }
    ]
}
var luch5 : Line = Line {
    startX: 57
    startY: 25
    endX: 112
    endY: 68
    stroke: Color.YELLOW
    transforms: [
            Rotate{
                pivotX:155
                pivotY:105
                angle:bind luch5Angle
            }
    ]

}
var luch6 : Line = Line {
    startX: 240
    startY: 25
    endX: 185
    endY: 68
    stroke: Color.YELLOW
    transforms: [
            Rotate{
                pivotX:155
                pivotY:95
                angle:bind luch6Angle
            }
    ]

}
var luch7 : Line = Line {
    startX: 235
    startY: 175
    endX: 183
    endY: 127
    stroke: Color.YELLOW
    transforms: [
            Rotate{
                pivotX:155
                pivotY:75
                angle:bind luch7Angle
            }
    ]
}
var luch8 : Line = Line {
    startX: 57
    startY: 175
    endX: 115
    endY: 127
    stroke: Color.YELLOW
    transforms: [
            Rotate{
                pivotX:155
                pivotY:105
                angle:bind luch8Angle
            }
    ]
}
var sky: ImageView = ImageView {
        x: 275
        y: 8
    image: Image
    {
            url: "{__DIR__}3.png"
            }
    onMouseClicked: function( e: MouseEvent ):Void {
        transTransition.play();
    }
      }
var flow: ImageView = ImageView {
        x: 270
        y: 260
    image: Image
    {
            url: "{__DIR__}1.png"
            }
   onMouseClicked: function( e: MouseEvent ):Void {
        scaleTransition.play();
    }
    }
var steb: ImageView = ImageView {
        x: 150
        y: 220
    image: Image
    {
            url: "{__DIR__}2.png"
            }
    onMouseClicked: function( e: MouseEvent ):Void {
        fadeTransition.play();
    }
    }

var b : Boolean = true;
var timeline : Timeline = Timeline{
    repeatCount:4
    autoReverse:true
    keyFrames: [
         at(3s){
                 luch1Angle=>30;
                 b => true;
                 }
         at(3s){
                 luch2Angle=> 30;
                }
         at(3s){
                 luch3Angle=>30;
                 }
         at(3s){
                 luch4Angle=>30;
                 }
         at(3s) {
                 luch5Angle=>30;
                 }
         at(3s){
                 luch6Angle=>30;
                 }
         at(3s) {
                 luch7Angle=>30;
                 }
         at(3s) {
                 luch8Angle=>30;
                 }


              ]
         }
var fadeTransition = FadeTransition {
    duration: 3s
    node: steb
    fromValue: 1.0
    toValue: 0.1
    repeatCount:4
    autoReverse: true
}

var transTransition = TranslateTransition {
    duration: 2s
    node: sky
    byX: 200
    byY: 35
    repeatCount:4
    autoReverse: true
}
var scaleTransition = ScaleTransition {
    duration: 4s
    node: flow
    byX: 0.5
    byY: 0.5
    repeatCount: 4
    autoReverse: true
}

Stage{
  title: " green "
  scene:
     Scene{
       fill: Color.WHEAT
       content:[
        ImageView{
		    image: Image{
			       url:  "{__DIR__}green.jpg"

		     }

        }
     sun,
     luch1,
     luch2,
     luch3,
     luch4,
     luch5,
     luch6,
     luch7,
     luch8,
     sky,
     flow,
     steb
     ]
     }
}